package volatileT;

import java.util.concurrent.TimeUnit;

/**
 * @author lyx
 * @Date 2021/6/27 10:01
 */
public class demo1 {
    private volatile static int num =0;
    public static void main(String[] args) throws InterruptedException {
            new Thread(()->{
                while(num==0){
                }
            },"A").start();
            //让线程睡2s
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        num=1;
        System.out.println(num);
    }
}
